/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lixo;

import br.com.geftu.model.Projeto;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import com.towel.bean.Formatter;
//import com.towel.el.annotation.Resolvable;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author jorgenei
 */
@Entity
@Table(name = "tb_modulo", catalog = "bddefeitos", schema = "public")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Modulo.findAll", query = "SELECT t FROM Modulo t"),
    @NamedQuery(name = "Modulo.findByIdmod", query = "SELECT t FROM Modulo t WHERE t.idmod = :idmod"),
    @NamedQuery(name = "Modulo.findByModulo", query = "SELECT t FROM Modulo t WHERE t.modulo = :modulo"),
    @NamedQuery(name = "Modulo.findByRelease", query = "SELECT t FROM Modulo t WHERE t.release = :release"),
    @NamedQuery(name = "Modulo.findByDtalteracao", query = "SELECT t FROM Modulo t WHERE t.dtalteracao = :dtalteracao"),
    @NamedQuery(name = "Modulo.findByExcluido", query = "SELECT t FROM Modulo t WHERE t.excluido = :excluido")})
public class ModuloOldxb implements Serializable {
    private static long serialVersionUID = 1L;

    /**
     * @return the serialVersionUID
     */
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    /**
     * @param aSerialVersionUID the serialVersionUID to set
     */
    public static void setSerialVersionUID(long aSerialVersionUID) {
        serialVersionUID = aSerialVersionUID;
    }
    @Id
    @Basic(optional = false)
    @Column(name = "idmod", nullable = false)
    //@Resolvable(colName = "ID")
    private Integer idmod;
    //@Resolvable(colName = "Modulo")
    @Column(name = "modulo", length = 2147483647)
    private String modulo;
    @Column(name = "release", length = 2147483647)
    //@Resolvable(colName = "Release")
    private String release;
    
    @Column(name = "dtalteracao", length = 2147483647)
    //@Resolvable(colName = "dtalteracao", formatter = DateFormatter.class)
    //private GregorianCalendar dtalteracao;
    private String dtalteracao;
    @Column(name = "excluido")
    private Boolean excluido;
    @ManyToOne (fetch= FetchType.EAGER, optional = false)
    @Cascade(CascadeType.SAVE_UPDATE)
    @JoinColumn(name = "idproj", updatable=true)
    @Fetch(FetchMode.JOIN)
    //@Resolvable(colName="Projeto")
    private Projeto projeto;

    public ModuloOldxb() {
    }
    
    public ModuloOldxb(String modulo, String release, String dtalteracao, Object projeto) {
        this.modulo = modulo;
        this.release = release;
        this.dtalteracao = dtalteracao;
        //
        this.projeto = (Projeto) projeto;
    }

    /**
     * @param dtalteracao the dtalteracao to set
     */
    public void setDtalteracao(String dtalteracao) {
        this.dtalteracao = dtalteracao;
    }
    
    private class DateFormatter implements Formatter {
	SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");

	@Override
	public String format(Object arg0) {
		return format.format(((GregorianCalendar) arg0).getTime());
	}

	@Override
	public String getName() {
		return "date";
	}

	@Override
	public Object parse(Object arg0) {
		GregorianCalendar cal = new GregorianCalendar();
		try {
                        cal.setTime(format.parse(arg0.toString()));
		} catch (ParseException e) {
                        e.printStackTrace();
		}
		return cal;
	}

    }    

    public ModuloOldxb(Integer idmod) {
        this.idmod = idmod;
    }

    public Integer getIdmod() {
        return idmod;
    }

    public void setIdmod(Integer idmod) {
        this.idmod = idmod;
    }

    public String getModulo() {
        return modulo;
    }

    public void setModulo(String modulo) {
        this.modulo = modulo;
    }

    public String getRelease() {
        return release;
    }

    public void setRelease(String release) {
        this.release = release;
    }

    public String getDtalteracao() {
        return dtalteracao;
    }

    public Boolean getExcluido() {
        return excluido;
    }

    public void setExcluido(Boolean excluido) {
        this.excluido = excluido;
    }

    public Projeto getProjeto() {
        return projeto;
    }    

    public void setProjeto(Projeto projeto) {
        this.projeto = projeto;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getIdmod() != null ? getIdmod().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ModuloOldxb)) {
            return false;
        }
        ModuloOldxb other = (ModuloOldxb) object;
        if ((this.getIdmod() == null && other.getIdmod() != null) || (this.getIdmod() != null && !this.idmod.equals(other.idmod))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ""+ getIdmod();
    }
    
    public void printAttrs() {
        System.out.println("Projeto: " + getProjeto().getNomeprojeto());
	System.out.println("Modulo: " + getModulo());
	System.out.println("Release: " + getRelease());
	System.out.println("DTAlt: " + getDtalteracao());
    }    
    
}
